<?php

namespace app\admin\controller;

use app\admin\model\Oauth;
use app\common\controller\Send;
use app\admin\model\Feedback AS FeedbackModel;

class Feedback extends Base
{
    use Send;

    /**
     * 反馈列表
     * @return \think\response\View
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $search = input('');
        $oauthId = isset($search['oauth_id']) ? $search['oauth_id'] : 0;
        $dealStatus = isset($search['deal_status']) ? $search['deal_status'] : -1;
        $search = [
            'oauth_id' => $oauthId,
            'deal_status' => $dealStatus
        ];

        $where = [];
        $oauth = [
            'id' => 0,
            'nickname' => '',
            'phone' => '',
        ];
        if ($search['oauth_id'] > 0) {
            $oauth = Oauth::getOne($search['oauth_id']);
            $where[] = ['oauth_id', '=', $search['oauth_id']];
        }

        if ($search['deal_status'] != null && $search['deal_status'] != -1) {
            $where[] = ['deal_status', '=', $search['deal_status']];
        }

        $model = FeedbackModel::getList($where);
        return view('index', [
            'model' => $model['model'],
            'count' => $model['count'],
            'search' => $search,
            'deal_status' => FeedbackModel::attributes('deal_status'),
            'oauth' => $oauth
        ]);
    }

    /**
     * 修改状态
     * @param $id
     * @return array
     */
    public function disabled($id)
    {
        FeedbackModel::dealOne($id);
        return self::sendResult(self::$okCode, [
            'url' => url('index'),
        ]);
    }
}
